﻿package com.victim.snake.graphics.mainClass
{
	import com.victim.snake.graphics.ChatSprite;
	import flash.text.TextFormat;
	import com.victim.snake.style.TextStyle;
	import fl.controls.ComboBox;
	import flash.display.Sprite;
	import flash.display.LoaderInfo;
	import flash.events.MouseEvent;
	import com.victim.snake.style.ComboBoxUpSkin;
	import com.victim.snake.style.ComboBoxOverSkin;
	import com.victim.snake.util.Loader;
	import fl.controls.listClasses.CellRenderer;
	import com.victim.snake.style.ComboBoxCellRendererUpSkin;
	import com.victim.snake.style.ComboBoxCellRenderer;
	import com.victim.snake.style.InputTextUpSkin;
	import com.victim.snake.style.OutputTextAreaUpSkin;
	import com.victim.snake.style.MainThumbIcon;
	
	
	import flash.events.Event;
	import fl.controls.ScrollPolicy;
	import fl.controls.ScrollBar;
	import fl.events.ScrollEvent;
	import flash.display.Bitmap;
	import com.victim.snake.graphics.mainClass.chat.ImageLoader;
	
	//主界面聊天面版
	public class Chat extends ChatSprite
	{		
		
		
		
		public function Chat(w:int):void{
			super(w);
			
			//输出框
			this.outputTextArea.width=527;
			this.outputTextArea.height=70;
			this.outputTextArea.setStyle("upSkin",OutputTextAreaUpSkin);
			
			
			
			//输出框滚动条
			this.scrollBar.x=this.outputTextArea.x+this.outputTextArea.width+10;
			this.scrollBar.y=this.outputTextArea.y;
			this.scrollBar.height=this.outputTextArea.height;						
			this.scrollBar.setStyle("thumbIcon",MainThumbIcon);	//设置滚动按钮上的缩略图(为空)
			ImageLoader.trackUpSkinLoader();
			ImageLoader.upArrowUpSkinLoader();
			ImageLoader.upArrowOverSkinLoader();
			ImageLoader.downArrowUpSkinLoader();
			ImageLoader.downArrowOverSkinLoader();
			ImageLoader.thumbUpSkinLoader();
			ImageLoader.thumbOverSkinLoader();
			
			
			
			
			//频道选择框
			this.comboBox.x = 2;
			this.comboBox.y = this.outputTextArea.height + 7;
			this.comboBox.width=108;									
			this.comboBox.setStyle("overSkin",new ComboBoxOverSkin());
			this.comboBox.setStyle("downSkin",new ComboBoxUpSkin());		
			this.comboBox.dropdown.setStyle("cellRenderer",ComboBoxCellRenderer);
			this.comboBox.textField.setStyle("textFormat",TextStyle.getChatComboBoxStyle());
			this.comboBox.setStyle("textFormat",TextStyle.getChatComboBoxStyle());
			this.comboBox.dropdown.setStyle("textFormat",TextStyle.getChatComboBoxStyle());
			ImageLoader.comboBoxUpSkinLoader();
			this.dataProvider.removeAll();
			this.dataProvider.addItem({label:"世界",data:"all"});
			
			//this.dataProvider.addItem({label:"房间",data:"room"});

			//输入框
			this.inputText.width=350;			
			this.inputText.x = this.comboBox.x + this.comboBox.width+10;
			this.inputText.y = this.comboBox.y + 1;
			this.inputText.setStyle("upSkin",InputTextUpSkin);
			this.inputText.setStyle("focusRectSkin",InputTextUpSkin);
			this.inputText.setStyle("textFormat",TextStyle.getMainChatInputStyle());
			
			
			
		}
		
		
		
		
		//发送按扭加载事件
		override public function sendButUpSkinLoaderEvent(event:Event):void
		{
			//发送图标
			new Loader("image/main/chat/mainChatSendButton.png",this.sendButUpSkinLoaderEventA);
			new Loader("image/main/chat/mainChatSendButtonOver.png",this.sendButOverSkinLoaderEventA);
		}
		
		//发送按扭加载事件
		public function sendButUpSkinLoaderEventA(event:Event):void
		{
			sendButUpSkinLoader = LoaderInfo(event.target).loader;
			sendButUpSkinLoader.width = 45;
			sendButUpSkinLoader.height = 19;
			sendButUpSkinLoader.x = this.inputText.x+this.inputText.width+12;
			sendButUpSkinLoader.y = this.inputText.y-1;

			sendButUpSkinLoader.addEventListener(MouseEvent.CLICK,sendEvent);
			sendButUpSkinLoader.addEventListener(MouseEvent.MOUSE_OVER,sendButUpSkinLoaderMouseOverA);
			
			
			this.addChild(sendButUpSkinLoader);

		}
		
		//发送按扭加载事件
		public function sendButOverSkinLoaderEventA(event:Event):void
		{
			sendButOverSkinLoader = LoaderInfo(event.target).loader;
			sendButOverSkinLoader.width = 45;
			sendButOverSkinLoader.height = 19;
			sendButOverSkinLoader.x = this.inputText.x+this.inputText.width+12;
			sendButOverSkinLoader.y = this.inputText.y-1;

			sendButOverSkinLoader.addEventListener(MouseEvent.CLICK,sendEvent);
			sendButOverSkinLoader.addEventListener(MouseEvent.MOUSE_OUT,sendButUpSkinLoaderMouseOutA);
			//this.addChild(sendButOverSkinLoader);

		}
		//发送按钮鼠标事件
		public function sendButUpSkinLoaderMouseOverA(e:Event):void{
			if(this.sendButOverSkinLoader!=null){
				this.addChild(this.sendButOverSkinLoader);
			}
		}
		//发送按钮鼠标事件
		public function sendButUpSkinLoaderMouseOutA(e:Event):void{			
			this.addChild(this.sendButUpSkinLoader);			
		}
		
		
		//添加聊天消息
		override public function addTalkMsg(talkUser:String,talkContent:String):void{
			row+=1;
			var ht:String=this.outputTextArea.htmlText;
			ht+="<p><a href='event:" + talkUser + "'><font color='#ffff00'><b>[" + talkUser + "]</b></font></a><font color='#ffffff'>："+talkContent+"</font></p>";
			if(row>20){
				ht=ht.replace(this.outputTextPattern,"");
			}
			
			this.outputTextArea.htmlText =  ht
			if(this.outputTextArea.maxVerticalScrollPosition>1){
				this.outputTextArea.verticalScrollPosition=this.outputTextArea.maxVerticalScrollPosition;
				this.scrollBar.maxScrollPosition=this.outputTextArea.maxVerticalScrollPosition;
				this.scrollBar.scrollPosition=this.outputTextArea.maxVerticalScrollPosition;						
			}
		}
		


		
	}
}